package com.ms.game.rebate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.ms.game.bank.container.BankInfoBin;
import com.ms.game.common.container.BasicSettingServerBinUtil;
import com.ms.game.purchase.bin.PurchaseType;

public class RebateUtil {
	/**
	 * 取得包月刷新的時間格式
	 * @return
	 */
	public static String getMonthlyFeeFlushTimeFormat(){
		return BasicSettingServerBinUtil.getEventFlsuhTime(BasicSettingServerBinUtil.MONTHLY_DAILY_AWARD_FLUSH_TIME_FORMAT);
	}

	/**
	 * 取得包週刷新的時間格式
	 * @return
	 */
	public static String getBuyFeeFlushTimeFormat(int buyFeeType){
		if (buyFeeType == PurchaseType.MONTH) {
			return BasicSettingServerBinUtil.getEventFlsuhTime(BasicSettingServerBinUtil.MONTHLY_DAILY_AWARD_FLUSH_TIME_FORMAT);
		} else if (buyFeeType == PurchaseType.WEEK) {
			return BasicSettingServerBinUtil.getEventFlsuhTime(BasicSettingServerBinUtil.WEEKLY_DAILY_AWARD_FLUSH_TIME_FORMAT);
		}
		return null;
	}
	
	/**
	 * 取的抽佣刷新的時間格式
	 * @return
	 */
	public static String getCommisonFlushTimeFormat(){
		return BasicSettingServerBinUtil.getEventFlsuhTime(BasicSettingServerBinUtil.DAILY_FLUSH_REBATE_TABLE_TIME_FORMAT);
	}
	
	/**
	 * 取得包月天數
	 * @return
	 */
	public static Integer getMonthlyFeeDays(){
		return BankInfoBin.getInstance().getMonthlyFeeDailyPay().size();
	}

	/**
	 * 取得包週天數
	 * @return
	 */
	public static Integer getBuyFeeDays(int buyFeeType){
		return BankInfoBin.getInstance().getFeeInfos().get(buyFeeType).getFeeDailyPay().size();
	}
	
	/**
	 * 取的抽佣保存天數
	 * @return
	 */
	public static Integer getCommisonKeepDays(){
		return BasicSettingServerBinUtil.getEventKeepDays(BasicSettingServerBinUtil.COMMISON_KEEP_DAYS);
	}
	
	/**
	 * 算出抽佣屬於哪一天
	 * @return
	 */
	public static Date getCommisonBelongsDate(){
		String flushTimeFormat = getCommisonFlushTimeFormat();
		String[] timeArray = flushTimeFormat.split("-");

		Date now = new Date();
		Date date = new Date();
		date.setHours(Integer.parseInt(timeArray[0]));
		date.setMinutes(Integer.parseInt(timeArray[1]));
		date.setSeconds(Integer.parseInt(timeArray[2]));
		
		if(now.getTime() - date.getTime() > 0){
			date.setHours(date.getHours() + 24);
		}
		
		SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
		try {
			date = formater.parse(formater.format(date));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}
	
	/**
	 * 抽佣到期日 
	 * 假設今天 2016/04/29 那到期日就是 2016/05/28
	 * @return
	 */
	public static Date getCommisonEndDate(){
		Date date = getCommisonBelongsDate();
		//當日也算所以+1
		date.setDate(date.getDate() + getCommisonKeepDays() - 1);
		return date;
	}
}
